import request from "@/utils/request";

export function fileCheck(data) {
  return request.post("/api/file/fileCheck", data);
}
export function fileUpload(data, progressBlack) {
  return request.post("/api/file/fileUpload", data, {
    onUploadProgress: function (progressEvent) {
      let complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0;
      if (progressBlack) {
        progressBlack(complete);
      }
    },
  });
}
export function fileUploadMerge(data) {
  return request.post("/api/file/fileUploadMerge", data);
}

/**
 * 用户
 */
export function login(data) {
  return request.post("/api/user/login", data);
}
export function roles(data) {
  return request.post("/api/user/roles", data);
}
export function userList(data) {
  return request.post("/api/user/userList", data);
}
/**
 *
 * @param {username, password, surePassword} data
 * @returns
 */
export function addUser(data) {
  return request.post("/api/user/addUser", data);
}
/**
 * 文件list
 * pageNum
 * pageSize
 */
export function fileList(data) {
  return request.post("/api/file/list/fileList", data);
}
/**
 *
 * @param {fileListId, downloadFileName = "", downloadSpeed, expirationTime} data
 * @returns
 */
export function downloadFileAdd(data) {
  return request.post("/api/file/list/downloadFileAdd", data);
}
/**
 *
 * @param {id} data
 * @returns
 */
export function deleteDownloadFile(data) {
  return request.post("/api/file/list/deleteDownloadFile", data);
}
/**
 *
 * @param {downloadFileName, downloadSpeed, expirationTime, downloadFileId} data
 * @returns
 */
export function updateDonwloadFile(data) {
  return request.post("/api/file/list/updateDonwloadFile", data);
}
/**
 * 下载历史
 * @param {startTime = "", endTime = ""} id
 * @returns
 */
export function downloadHistoryList(data) {
  return request.post("/api/file/history/downloadHistoryList", data);
}
/**
 * 下载地址拼接
 */
export function downLoadPathStr(id) {
  return window.location.origin + "/api/file/downloadFile/" + id;
}

/**
 * 聊天功能
 */
export function chatWs(callback) {
  return request.ws("/chatWs", callback);
}
